package com.atguigu.day05;

import java.util.Arrays;
import java.util.Scanner;

public class Test_3 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int x;
        int y;
        System.out.println("请输入组数:");
        x = s.nextInt();

        int[] Lofy = new int[x];
        for (int i = 0; i < x; i++) {
            System.out.println("请输入第" + (i + 1) + "组的人数:");
            Lofy[i] = s.nextInt();
        }
        int maxOfY = Lofy[0];
        for (int i = 0; i < Lofy.length - 1; i++) {
            maxOfY = INTcompareMAX(Lofy[i], Lofy[i + 1]);
        }
        double[][] score = new double[x][maxOfY];
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < Lofy[i]; j++) {
                System.out.println("请输入第" + (i + 1) + "组" + (j + 1) + "号的成绩:");
                score[i][j] = s.nextInt();
            }
//            System.out.println(Arrays.toString(score[i]));
        }
        double[] maxOfL = new double[x];
        double[] minOfL = new double[x];
        for (int j = 0; j < score.length; j++) {
            maxOfL[j] = comparedoulemax(score[j], Lofy[j]);
        }
        for (int j = 0; j < score.length; j++) {
            minOfL[j] = comparedoulemin(score[j], Lofy[j]);
        }
        System.out.println("每个组的最高分" + Arrays.toString(maxOfL));
        System.out.println("每个组的最低分" + Arrays.toString(minOfL));
        for (int i = 0; i < score.length; i++) {
            double sum = 0;
            for (int j = 0; j < Lofy[i]; j++) {
                sum += score[i][j];
            }
            System.out.println("第" + (i + 1) + "组的平均分是:" + (sum / Lofy[i]));
        }
        double maxOfAll = score[0][0];
        double minOfAll = score[0][0];
        int sum = 0;
        int num = 0;
        for (int i = 0; i < score.length; i++) {
            for (int j = 0; j < Lofy[i]; j++) {
                sum += score[i][j];
                num++;
                if (score[i][j] > maxOfAll)
                    maxOfAll = score[i][j];
                if (score[i][j] < minOfAll)
                    minOfAll = score[i][j];
            }
        }
        System.out.println("全班的最高分" + maxOfAll);
        System.out.println("全班的平均分:" + sum / num);
        System.out.println("全班的总人数:" + num);
    }

    static int INTcompareMAX(int d1, int d2) {
        return d1 > d2 ? d1 : d2;
    }

    static double comparedoulemax(double d1[], int Lofy) {
        double bet = d1[0];
        for (int j = 0; j < Lofy; j++) {
            for (int i = 0; i < Lofy - 1 - j; i++) {
                if (d1[i] < d1[i + 1]) {
                    bet = d1[i + 1];
                    d1[i + 1] = d1[i];
                    d1[i] = bet;
                }
            }
        }
        return d1[0];
    }

    static double comparedoulemin(double d1[], int Lofy) {
        double bet = d1[0];
        for (int j = 0; j < Lofy; j++) {
            for (int i = 0; i < Lofy - 1 - j; i++) {
                if (d1[i] > d1[i + 1]) {
                    bet = d1[i + 1];
                    d1[i + 1] = d1[i];
                    d1[i] = bet;
                }
            }
        }
        return d1[0];
    }
}
